package com.eimf.saf.common.commons.i18n;

/**
 * @author eden
 * @date 2013-11-13 下午5:42:28
 * @Description: 国际化资源工具类
 */
public class I18nUtil
{

    private final static String START_SYMBOL = "{";
    private final static String END_SYMBOL = "}";

    private I18nUtil()
    {
        super();
    }

    /**
     * 返回组装后的文本。<br>
     * 示例：{200}
     * 
     * @param text
     * @return
     */
    public static String createTextChunk(final Object text)
    {
        final StringBuilder sb = new StringBuilder();
        if (text == null)
        {
            sb.append(I18nUtil.START_SYMBOL).append(I18nUtil.END_SYMBOL);
        } else
        {
            if (text instanceof String)
            {
                final String temp = (String) text;
                if (!temp.trim().startsWith(I18nUtil.START_SYMBOL))
                {
                    sb.append(I18nUtil.START_SYMBOL);
                }

                sb.append(text);

                if (!temp.trim().endsWith(I18nUtil.END_SYMBOL))
                {
                    sb.append(I18nUtil.END_SYMBOL);
                }
            } else
            {
                sb.append(I18nUtil.START_SYMBOL).append(text).append(I18nUtil.END_SYMBOL);
            }
        }
        return sb.toString();
    }
}
